﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Fonlow.BetterRobocopyGui;
using System.Reflection;

namespace TestBetter
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestGetDefaultValueOfCommandBuilder()
        {
            Options options = new Options();
            options.SlashCopy = CopyFlags.A | CopyFlags.D;

            ParametersBuilder_Accessor b = new ParametersBuilder_Accessor(options);

            PropertyInfo[] propertiesArray = options.GetType().GetProperties();
            foreach (PropertyInfo p in propertiesArray)
            {
                if (p.Name == "SlashCopy")
                {
                    CopyFlags flags = (CopyFlags)ParametersBuilder_Accessor.GetDefaultValue(p);
                    Assert.IsTrue(flags == CopyFlags.None);
                    CopyFlags kk = (CopyFlags)p.GetValue(options, null);
                    Assert.IsTrue(options.SlashCopy == kk);
                    return;
                }
            }

            Assert.Fail("Not found.");
        }

        [TestMethod]
        public void TestGetParametersOfCommandBuilder()
        {
            Options options = new Options();
            options.SlashCopy = CopyFlags.A | CopyFlags.D;

            ParametersBuilder b = new ParametersBuilder(options);
            List<string> parameters = b.GetDefinedParameters();
            Assert.IsTrue(parameters.Count == 1, "All properties of non strhing type should have a default value.");
            Assert.IsTrue(parameters[0] == "/COPY:DA");

        }

        [TestMethod]
        public void TestRoboCopyCommand()
        {
            RobocopyCommand command = new RobocopyCommand();
            command.Load(
                "robocopy \"\\\\here\\OK here\" \"d\\:\\there is\\A Dir\" file1 \"file 2\" /Z   /DCOPY:T /A-:RASCN /256   /XF abe defg \"c:\\here and there\\kk.doc\" /MAX:23 /Log+:\"c:\\some where\\kk.log\" /CopyAll");
            Assert.IsTrue(command.Source == "\"\\\\here\\OK here\"");
            Assert.IsTrue(command.Destination == "\"d\\:\\there is\\A Dir\"");
            Assert.IsTrue(command.Files == "file1 \"file 2\"");

            Assert.IsTrue(command.RobocopyOptions.SlashZ);
            Assert.IsTrue(command.RobocopyOptions.SlashDCopyT);
            Assert.IsTrue(command.RobocopyOptions.SlashAMinus == (Rashcneto.R | Rashcneto.A | Rashcneto.S | Rashcneto.C | Rashcneto.N));
            Assert.IsTrue(command.RobocopyOptions.Slash256);
            Assert.IsTrue(command.RobocopyOptions.SlashXf == "abe defg \"c:\\here and there\\kk.doc\"");
            Assert.IsTrue(command.RobocopyOptions.SlashMax == 23);
            Assert.IsTrue(command.RobocopyOptions.SlashLogPlus == "\"c:\\some where\\kk.log\"");
        }
    }
}
